package net.lesscoding.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.lesscoding.common.Result;
import net.lesscoding.common.ResultFactory;
import net.lesscoding.entity.OutPathConfig;
import net.lesscoding.service.OutPathConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @author eleven
 * @date  2022-08-05 15:30:41
 * @description out_path_config 输出路径配置表 控制器
 * Generated By: lesscoding.net basic service
 * Link to: <a href="https://lesscoding.net">https://lesscoding.net</a>
 * mail to:2496290990@qq.com zjh292411@gmail.com admin@lesscoding.net
 */
@RestController
@RequestMapping("/outPathConfig")
@Api(tags = "输出路径配置表")
public class OutPathConfigController {

    @Autowired
    private OutPathConfigService outPathConfigService;

    @GetMapping("/page")
    @ApiOperation(value = "分页查询输出路径配置表数据",notes = "分页查询描述")
    public Result getPageByLike(OutPathConfig outPathConfig){
        return outPathConfigService.getPageByLike(outPathConfig);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询输出路径配置表详情",notes = "详情查询描述")
    public Result getOutPathConfigById(@PathVariable("id") Integer id){
        return ResultFactory.success(outPathConfigService.getById(id));
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "新增或更新输出路径配置表详情",notes = "编辑描述")
    public Result saveOrUpdateOutPathConfigById(@RequestBody OutPathConfig outPathConfig){
        if(outPathConfigService.saveOrUpdate(outPathConfig)){
            return ResultFactory.success("操作成功");
        }else{
            return ResultFactory.failed("操作失败");
        }
    }

    /**
    * 当前为逻辑删除，
    * 需要在实体类逻辑删除字段上添加 @TableLogic(value = "1",delval = "0")
    * 对应你的逻辑删除值，
    * 真删除调用delById(id)即可
    * @param id
    * @return
    */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除输出路径配置表详情",notes = "根据id删除")
    public Result delOutPathConfigById(@PathVariable("id") Integer id){
        if(outPathConfigService.removeById(id)){
            return ResultFactory.success("操作成功");
        }else{
            return ResultFactory.failed("操作失败");
        }
    }

    @GetMapping("/template")
    @ApiOperation(value = "下载输出路径配置表导入模板")
    public void downloadTemplate(HttpServletResponse response){
        outPathConfigService.downloadTemplate(response);
    }

    @PostMapping("/import")
    @ApiOperation(value = "从Excel模板导入输出路径配置表数据")
    public Result import4Excel(MultipartFile file){
        return outPathConfigService.import4Excel(file);
    }

    @PostMapping("/export")
    @ApiOperation(value = "导出输出路径配置表列表数据到Excel表格")
    public void export2Excel(@RequestBody OutPathConfig outPathConfig, HttpServletResponse response){
        outPathConfigService.export2Excel(outPathConfig,response);
    }


}
